package scu.maqiang.systemidentification;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Arrays;

public class RandomSeries {
    public static double[] uniform(double a, double b, int N) {
        BigDecimal A = BigDecimal.valueOf(Math.pow(5.0, 17.0));
        BigDecimal x0 = BigDecimal.valueOf(1L);
        BigDecimal M = BigDecimal.valueOf(Math.pow(2.0, 42.0));
        double[] series = new double[N];
        for(int i = 0; i < N; i++){
            BigDecimal x2 = A.multiply(x0);
            BigDecimal x1 = mod(x2, M);
            BigDecimal v = x1.divide(M);
            series[i] = a + (b - a) * v.doubleValue();
            x0 = x1;
        }
        return series;
    }
    public static BigDecimal mod(BigDecimal x, BigDecimal M) {
        BigDecimal q = BigDecimal.valueOf(x.divide(M).longValue());
        return x.subtract(q.multiply(M));
    }

    public static void main(String[] args) {
        double[] series = uniform(0.0, 1.0, 100);
        System.out.println(Arrays.toString(series));

    }
}
